logMeIn = function() {
	console.log("login");
	$(".response p.text").html("");
	$(".response, .response p.ajax-loader, .response p.text").show();
	$.ajax({
		type: "POST",
		url: "index.php?controller=FrontOffice&method=ajaxMethod",
		data: $('#loginForm').serialize()+"&getuser=true",
		success: function(data){
			if(data['returnDatas']=="1") {
				$(".response p.text").html("Connexion r&eacute;ussie");
				window.location.href = "index.php?controller=BackOffice&method=clearMethod&module=news";
			}
			else {
				$(".response p.text").show();
				$(".response p.text").html("Mauvaise identification");
			}
			$(".response, .response p.ajax-loader, .response p.text").delay(2000).hide(0);
			$(".response p.text").delay(2000).queue(function(){$(this).html("");});
		},
		dataType: "json"
	});
	return false;
}

init_response = function() {
	$(".response p.text").html("");
	$(".clickPrevent").fadeIn();
}

kill_response = function() {
	$(".clickPrevent").delay(2000).fadeOut();
	$(".response p.text").delay(2600).queue(function(){$(this).html("");});
}

reloadView = function(include, module) {
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=reload",
		success: function(data){
			$(".response .text").html("Rechargement des donn&eacute;es...");
			$(include).html(data['view']);
			kill_response();
		},
		dataType: "json"
	});
	return false;
}

createItem = function(module) {
	init_response();
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=create&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Ajout effectu&eacute");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}

deleteItem = function(id, module) {
	init_response();
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=delete&id="+id+"&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Suppression effectu&eacutee");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}

updateItem = function(id, module) {
	init_response();
	form = $("form[class='"+id+"']").serializeArray();
	console.log(form);
	form = JSON.stringify(form);
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=update&form="+form+"&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Modification effectu&eacutee");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}

deleteGroup = function(module) {
	delArray = new Array();
	$("input:checked[class='delete']").each(function(){
		item = $(this).parent().attr("class");
		delArray.push(item);
	});
	delArray = JSON.stringify(delArray);
	init_response();
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=deletegroup&group="+delArray+"&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Suppression effectu&eacutee");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}

updateAll = function(module) {
	init_response();
	var formArray = new Array();
	$("form").each(function(){
		form = $(this).serializeArray();
		formArray.push(form);
	});
	formArray = JSON.stringify(formArray);
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "module="+module+"&action=updateall&formArray="+formArray+"&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Modification effectu&eacutee");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}

delete_img = function(img, module) {
	init_response();
	var imglink = img.replace(/^url|[\(\)]/g, "");
	$.ajax({
		type: "POST",
		url: "index.php?controller=BackOffice&method=ajaxMethod",
		data: "deleteimg=true&imglink="+imglink+"&token="+$('#token').val(),
		success: function(data){
			if (data['returnDatas']=="1") {
				$(".response p.text").html("Suppression effectu&eacutee");
				reloadView("#moduleInclude", module);
			}
			else {
				$(".response p.text").html("Erreur");
			}
		},
		dataType: "json"
	});
	return false;
}